package ua.mihaylenko.app.ui.preloader 
{
	import flash.display.Sprite;
	import flash.events.ProgressEvent;
	import ua.mihaylenko.app.controller.APPStage;
	import ua.mihaylenko.app.ui.window.UIWindow;
	import vk.gui.Box;
	/**
	 * ...
	 * @author Mihaylenko A.L.
	 */
	public class UIPreloader extends UIWindow
	{
		private var _cUIBox:Box;
		private var _smcTotalBar:Sprite;
		private var _smcFGBar:Sprite;
		private var _smcBoxContent:Sprite;
		public function UIPreloader() 
		{
			
		}
		public function set title(sValue:String):void { if (_cUIBox)_cUIBox.title = sValue; }
		override public function innit(arguments:Array):void 
		{
			_smcBoxContent = new Sprite()
			_smcFGBar = new Sprite();
			_smcTotalBar = new Sprite();
			
			_smcBoxContent.addChild(_smcTotalBar);
			_smcBoxContent.addChild(_smcFGBar);
			
			_smcFGBar.graphics.beginFill(0x004A6F, 0);
			_smcFGBar.graphics.drawRect(0, 0, APPStage.gameResolution.x / 3, 50);
			_smcFGBar.graphics.endFill();
			_smcFGBar.graphics.lineStyle(2, 0x005680);
			_smcFGBar.graphics.drawRect(0, 0, APPStage.gameResolution.x / 3, 5);
			
			_smcTotalBar.graphics.beginFill(0x004A6F);
			_smcTotalBar.graphics.drawRect(0, 0, APPStage.gameResolution.x / 3, 5);
			_smcTotalBar.graphics.endFill();
			
			_smcTotalBar.scaleX = 0;
			
			_cUIBox = new Box(arguments[4], _smcBoxContent, 0, APPStage.gameResolution.x / 2, []);
			_cUIBox.x = 0;
			_cUIBox.y = 0;
			_cUIBox.visible = true;
			
			_smcBoxContent.x = (_cUIBox.width - _smcBoxContent.width) / 2;
			addChild(_cUIBox);
			return super.innit(arguments);
		}
		override public function get height():Number { 
			//return super.height; 
			return _cUIBox.height;
		}
		
		override public function set height(value:Number):void 
		{
			super.height = value;
		}
		override public function get width():Number { 
			//return super.width; 
			return _cUIBox.width;
		}
		
		override public function set width(value:Number):void 
		{
			//return _cUIBox.width;
			super.width = value;
		}
		public function onProgress(event:ProgressEvent):void
		{
			_smcTotalBar.scaleX = event.bytesLoaded / event.bytesTotal;
		}
		
	}

}